<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>rest参数替换arguments参数</title>
  </head>

  <body>

  </body>
  <script>
    //1.ES5的方式：arguments
    function getArr() {
      console.log(arguments); //类数组
    }
    getArr(1, 2, 3, 4, 5)
    //2.ES6:rest方法:
    //2.1 rest必须写在最后面， 且rest是一个真正的数组

    function add(x, y, ...rest) {
      //console.log(x, y, ...rest);
      console.log(x, y); //1 2
      rest.forEach((item) => {
        console.log(item); //3 4 5
      })
    }
    add(1, 2, 3, 4, 5)
  </script>

</html>